<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
    <script type="text/javascript" src="js/jquery.2.1.4.js"></script>
    <script>
        $(function () {
            $("#username").change(function () {
                $("#tip1").html("");
                var name = $("#username").val().trim();
                if (name != "") {
                    $.post("check", {username: name}, function (data) {
                        if (data== 1) {
                            $("#tip1").html("用户名已经存在");
                        }
                    })
                }
            });

        });
        valid = function () {
            var flag = false;
            if ($("#tip1").html() != "") {
                $("#tip2").html("");
                return false;
            }
            $("#tip1").html("");
            $("#tip2").html("");
            if ($("#username").val().trim() == "") {
                $("#tip1").html("用户名不能为空");
                flag = true;
            }
            if ($("#password").val().trim() == "") {
                $("#tip2").html("密码不能为空")
                flag = true;
            }
            if ($("#password").val().trim() != $("#password2").val().trim()){
                $("#tip2").html("密码输入不一致")
                flag = true;
            }
            if (flag) {
                return false;
            }

        }
        back = function () {
            window.location.href = "/jdbcmvc";
        }
    </script>
</head>
<body>
<fieldset style="width:350px; margin: 50px auto">
    <legend>请注册</legend>
    <form action="regist" method="post">
        <br>用户名：<input id="username" type="text" name="username"><span id="tip1" style="color: red"></span><br><br>
        密&nbsp;&nbsp;&nbsp;码：<input id="password" type="password" name="pwd"><span id="tip2"
                                                                                   style="color: red"></span><br>
        确&nbsp;&nbsp;&nbsp;认：<input id="password2" type="password"><br><br>
        <input type="submit" value="注册" onclick="return valid();"/>&nbsp;&nbsp;&nbsp;
        <input type="button" value="返回" onclick="back();">
    </form>
</fieldset>

</body>
</html>
